<?php
namespace app\index\controller\admin;

use app\index\controller\Base;
use think\Db;
use think\facade\Request;
use app\index\model\User;
use app\index\controller\Token;
// use think\cache\driver\Redis;

class Login extends Base
{
    //登录
    public function index()
    {

        // $token = Token::getToken(1);
        $params = input();
        $errM = $this->validate(
            $params,
            'app\index\validate\User'
        );
        if (true !== $errM) {
            return $this->errMsg($errM);
        } else {
            $user = User::where('user_no', $params["userNo"])->where('password', $params["password"])->find();
            if (empty($user)) {
                return $this->errMsg("用户账户或密码错误");
            } else {
                 $token =Token::getToken($user["id"]);
                // $redis = new Redis();
                // $redis->set('token',$token,10);
                return $this->okMsg("登录成功", $token);
            }
        }
    }
}
